﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JamesThew.Dashboard
{
    public partial class Payments : System.Web.UI.Page
    {
        public PaymentDB pdb;
        public String TableData;


        protected void Page_Load(object sender, EventArgs e)
        {
            /* QueryString Args */
            int Year = 2012, MonthMin = 0, MonthMax = 0, DateMin = 0, DateMax = 0;
            String Package = null, Method = null, Status = null;
            try
            {
                Year = JamesThew.Includes.Core.ParseInt(Request.QueryString["year"]);
                MonthMin = JamesThew.Includes.Core.ParseInt(Request.QueryString["monthmin"]);
                MonthMax = JamesThew.Includes.Core.ParseInt(Request.QueryString["monthmax"]);
                DateMin = JamesThew.Includes.Core.ParseInt(Request.QueryString["datemin"]);
                DateMax = JamesThew.Includes.Core.ParseInt(Request.QueryString["datemax"]);
                Package = Request.QueryString["package"];
                Method = Request.QueryString["method"];
                Status = Request.QueryString["status"];
            }
            catch (Exception ex) { 
                Year = 2012;
                MonthMin = 0;
                DateMin = 0;
                MonthMax = 0;
                DateMax = 0;
                Package = null;
                Method = null;
                Status = null;
            }
            if (Package == "") Package = null;
            if (Method == "") Method = null;
            if (Status == "") Status = null;

            this.pdb = new PaymentDB();
            List<String[]> ListPayment = this.pdb.Get(Year, MonthMin, MonthMax, DateMin, DateMax, 0, 0 ,0 , 0, Method, Package, Status);
            this.TableData = this.GenerateTableData(ListPayment);

            
        }

        protected String GenerateTableData(List<String[]> ListPayment) {
            String output = "";
            String RowStatus = "";

            foreach (String[] S in ListPayment)
            {
                if (S[9] == "approved") {
                    RowStatus = "success";
                }
                if (S[9] == "pending")
                {
                    RowStatus = "info";
                }
                if (S[9] == "canceled")
                {
                    RowStatus = "error";
                }
                output += "<tr class=\""+RowStatus+"\"><td><input type=\"checkbox\" name=\"" + S[3] + "\" /></td>";
                output += "<td>"+S[1]+"</td>";
                output += "<td>" + S[2] + "</td>";
                output += "<td>" + S[5] + "</td>";
                output += "<td>" + S[6] + "</em></td>";
                output += "<td>" + S[7] + "</em></td>";
                output += "<td>" + S[8] + "</em></td>";
                output += "<td>" + S[9] + "</em></td>";
                output += "</tr>";

            }
            return output;
        }
    }
}